package com.lgx.mobile.rest.group;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lgx.mobile.entity.GroupChatRecord;
import com.lgx.mobile.service.IGroupChatRecordService;

/**
 * 
 * @author xuyichen
 *
 */
@Controller
@RequestMapping("/getGroupChatRecord")
public class GetGroupChatRecordController {
	
	private static final Logger logger = Logger.getLogger(GetGroupChatRecordController.class);

	@Autowired
	IGroupChatRecordService groupChatRecordService;

	public IGroupChatRecordService getGroupChatRecordService() {
		return groupChatRecordService;
	}

	/**
	 * 圈子聊天记录查询
	 * @param groupId groupId is key
	 * @return 圈子内所有用户的聊天记录集合；0：该圈子没有聊天记录；1：参数异常，有参数为空
	 */
	@RequestMapping(value="/{groupId}",method=RequestMethod.GET)
	@ResponseBody
	public Object getGroupChatRecord(@PathVariable("groupId") String groupId){
		if(StringUtils.isNotBlank(groupId)){
			List<GroupChatRecord> groupChatRecordList = getGroupChatRecordService().findGroupChatRecordListByGroupId(Long.parseLong(groupId));
			if(groupChatRecordList.size() != 0){
				return groupChatRecordList;
			}else{
				if(logger.isDebugEnabled()){
					logger.debug("getGroupChatRecord faild groupId is error");
				}
//				"getGroupChatRecord faild please check groupId is exists";
				return "0";
			}
		}else{
			if(logger.isDebugEnabled()){
				logger.debug("getGroupChatRecord faild groupId is not filled");
			}
//		    "getGroupChatRecord faild please check groupId is filled";
			return "1";
		}
	}
}
